<?php defined('SYSPATH') or die('No direct script access.');

class Task_Exchange extends Minion_Task {
	/**
	 * Test action
	 *
	 * @param array $params
	 * @return void
	 */
	protected function _execute(array $params)
	{
		$url = 'http://www.cbr.ru/scripts/XML_daily.asp';

		$request = Request::factory($url)
			->headers('Accept','application/xml')
			->headers('Content-Type','application/xml')
			->method('GET');

		$response = $request->execute();
		//echo $response->body();
		$xml = new SimpleXMLElement($response->body());
		foreach($xml->Valute as $valute)
		{
			if ($valute->CharCode == 'CNY')
			{
				Model::factory('Book')->set_config('exchange',round(((str_replace(',','.',$valute->Value))/$valute->Nominal)*1.1,3));
				break;
			}
		}
		Minion_CLI::write(Minion_CLI::color(Model::factory('Book')->get_config('exchange',FALSE),'green'));
	}
} // End Exchange